#ifndef _MUNIX_REGISTEROBJ_H
#define	_MUNIX_REGISTEROBJ_H
/*******************************************************************************
 ** Name: registerobj.h                                                             **
 ** Description:              **
 **                                                                           **
 ** Open Source Initiative (OSI) Approved License                             **
 **                                                                           **
 ** The contents of this file are subject to the terms of the                 **
 ** Common Development and Distribution License, Version 1.0 only             **
 ** (the "License").  You may not use this file except in compliance          **
 ** with the License.                                                         **
 **                                                                           **
 ** You can find a copy of the license in the license.txt within              **
 ** this distribution or at http://www.munixos.net/licensing.                 **
 ** Software distributed under the License is distributed on an "AS IS"       **
 ** basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.           **
 ** See the License for the specific language governing permissions           **
 ** and limitations under the License.                                        **
 **                                                                           **
 ** When distributing Covered Code, include this CDDL header in each          **
 ** file and include the License file at $HOME/license.txt.                   **
 ** If applicable, add the following below this header, with the indicated    **
 ** fields enclosed by brackets "[]" replaced with your own identifying       **
 ** information: Portions Copyright [yyyy] [name of copyright owner]          **
 **                                                                           **
 **                                                                           **
 ** Copyright (c) 2009-2010  Barry Gian James <bjames@munixos.net>            **
 ** All rights reserved.                                                      **
 **                                                                           **
 ** Ref: $HeadURL$
 ******************************************************************************/
// Portions (C) 2011 OpenHouseware, LLC.
// All Rights Reserved

// $Id$
// Last Modified $DateTime$ by $Author$
#include "common.h"

extern const char __def_register_token;


/// This class creates an object at a particular address (usually
/// the address of, say, a general purpose register, etc.  Uses
/// placement new.
/// ex: RegisterObject * gpio1 = RegisterObject::Create(GPIO1);
///     gpio1.reg = 0xC0;
class RegisterObject
{
public:
	RegisterObject() { reg = 0x00; }
    RegisterObject(volatile uint8_t * r) { reg = r; }

    static RegisterObject * Create(volatile uint8_t * reg)
    {

        void * regaddr = (void*)(reg);
        RegisterObject * ro = new (regaddr) RegisterObject;
        return ro;
    }
    static void Destroy(RegisterObject * ro)
    {
        ro->~RegisterObject();
    }

	uint8_t operator [ ] (uint8_t idx);
private:
    volatile uint8_t *    reg;
};


#endif	/* _REGISTEROBJ_H */

